package com.gsmr.realm;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

	public class MultipleDataSource extends AbstractRoutingDataSource {

	public static final String dataSource1 = "dataSource1";
	public static final String dataSource2 = "dataSource2";
	public static final String dataSource3 = "dataSource3";
	public static final String dataSource4 = "dataSource4";
	public static final String dataSource5 = "dataSource5";
	public static final String dataSource6 = "dataSource6";
	public static final String dataSource7 = "dataSource7";
	public static final String dataSource8 = "dataSource8";
	public static final String dataSource9 = "dataSource9";
	public static final String dataSource10 = "dataSource10";
	public static final String dataSource11 = "dataSource11";
	public static final String dataSource12 = "dataSource12";
	public static final String dataSource13 = "dataSource13";
	public static final String dataSource14 = "dataSource14";
	public static final String dataSource15 = "dataSource15";
	public static final String dataSource16 = "dataSource16";
	public static final String dataSource17 = "dataSource17";
	public static final String dataSource18 = "dataSource18";
	public static final String dataSource19 = "dataSource19";
	public static final String dataSource20 = "dataSource20";

	public static String currentDataSource = dataSource1;

	public static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
	/*
	{
		byte[] buf = new byte[1024];
		
		InputStream is = this.getClass().getResourceAsStream("/jdbc.properties");
		int bytesRead = 0;
		try {
			while ((bytesRead = is.read(buf)) != -1) {
				String s = new String(buf, 0, bytesRead);
				System.out.print(s);
			}
		} catch (Exception e) {
			System.out.print(e);
		}
	}
	*/
	public static void setCustomerType(String customerType) {
		contextHolder.set(customerType);
	}

	public static String getCustomerType() {
		return contextHolder.get();
	}

	public static void clearCustomerType() {
		contextHolder.remove();
	}

	@Override
	protected Object determineCurrentLookupKey() {
		String s = getCustomerType();
		//System.out.print("当前使用的数据库是：");
		//System.out.println(s);
		return s;
	}
}